package com.qnzw.zjmy.home.ui.activity;


import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.android.volley.Request;
import com.android.volley.VolleyError;
import com.bumptech.glide.Glide;
import com.qnzw.zjmy.wxapi.WXEntryActivity;
import com.qnzw.zjmy.R;
import com.qnzw.zjmy.ad.MediationSplashAd;
import com.qnzw.zjmy.ad.inter.RewardAdSplasInter;
import com.qnzw.zjmy.ad.kaku.TaKuSplashAd;
import com.qnzw.zjmy.config.UrlAddressConfig;
import com.qnzw.zjmy.config.UrlConfig;
import com.qnzw.zjmy.home.HorizontalNtbActivity;
import com.qnzw.zjmy.home.ui.enums.RedisEnum;
import com.qnzw.zjmy.home.ui.model.TrandsName;
import com.qnzw.zjmy.home.ui.model.vo.BaseVo;
import com.qnzw.zjmy.utils.ViewUtils;
import com.qnzw.zjmy.volley.BaseActivity;
import com.qnzw.zjmy.volley.httpUtil.interfase.HUCCallBackInterfase;
import com.qnzw.zjmy.volley.state.HUCState;

public class SplashGmActivity extends BaseActivity implements RewardAdSplasInter {
    private FrameLayout llShow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_splash_gm);
        super.onCreate(savedInstanceState);
        //设置系统状态背景色
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(getResources().getColor(R.color.white));
        }
        ImageView logo = findViewById(R.id.splash_logo);
        Glide.with(this).load(R.drawable.icon_logo).into(logo);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        checkReward();

    }

    @Override
    public void initView() {
        super.initView();
        llShow = findViewById(R.id.ll_show);
    }

    //GM
    @Override
    public void onError() {
        loadDismiss();
        sendIntent(SplashGmActivity.this, HorizontalNtbActivity.class);
        finish();
    }

    @Override
    public void onAdClose() {
        loadDismiss();
        sendIntent(SplashGmActivity.this, HorizontalNtbActivity.class);
        finish();
    }

    @Override
    public void closeAlert() {
        loadDismiss();
    }


    private void checkReward() {
        BaseVo baseVo = new BaseVo();
        baseVo.setToken(getSharedPreferencesToken("token"));
        baseVo.setOaid(getSharedPreferences(RedisEnum.OAID.getKey()));

        hucRequestInterfase.executeStr(new HUCCallBackInterfase() {
            public void onSuccessfulStrType(int inputType, Object response) {
                loading();
                String key = getSharedPreferences(RedisEnum.TA_KU.getKey());
                if (RedisEnum.TA_KU.getValue().equals(key)) {
                    TaKuSplashAd taKuSplashAd = TaKuSplashAd.getInstance();
                    taKuSplashAd.setToken(getSharedPreferencesToken("token"));
                    taKuSplashAd.setmActivity(SplashGmActivity.this);
                    taKuSplashAd.load(SplashGmActivity.this, getSharedPreferences(RedisEnum.SPREAD_ITS_TAIL.getKey()), SplashGmActivity.this,llShow);
                } else {
                    MediationSplashAd mediationSplashAd = MediationSplashAd.getInstance();
                    mediationSplashAd.setRewardAdSplasInter(SplashGmActivity.this);
                    mediationSplashAd.setActivity(SplashGmActivity.this);
                    mediationSplashAd.showCacheSplashAd(llShow);
                }
            }
            @Override
            public void onFailStrType(int inputType, Object response) {
                loadDismiss();
                ViewUtils.showRisk(SplashGmActivity.this, response.toString(), getSharedPreferences(RedisEnum.APP_QQ_CUSTOMER_SERVICE.getKey()));
            }

            @Override
            public void onSuccessfulBitampType(int inputType, Bitmap response) {
                loadDismiss();
                ViewUtils.showRisk(SplashGmActivity.this, response.toString(), getSharedPreferences(RedisEnum.APP_QQ_CUSTOMER_SERVICE.getKey()));
            }

            @Override
            public void onErrorResponse(int inputType, VolleyError response) {
                loadDismiss();
                ViewUtils.showRisk(SplashGmActivity.this, response.toString(), getSharedPreferences(RedisEnum.APP_QQ_CUSTOMER_SERVICE.getKey()));
            }

            @Override
            public void onErrorLogin(int inputType, Object response) {
                loadDismiss();
                if (UrlAddressConfig.CHANNEL_TYPE==1) {
                    finish();
                    Intent intent = new Intent(SplashGmActivity.this, WXEntryActivity.class);
                    intent.putExtra("response",response.toString());
                    startActivity(intent);
                }
            }

            @Override
            public void onResetLogin(Object response) {
                loadDismiss();
                ViewUtils.showRisk(SplashGmActivity.this, response.toString(), getSharedPreferences(RedisEnum.APP_QQ_CUSTOMER_SERVICE.getKey()));
            }
        }, TrandsName.class, HUCState.HUC_REQEUST_CODE_5, Request.Method.POST, UrlConfig.URL_CHECK_REWARD, hucParameInterfase.getRequestParameter(baseVo), true);


    }

}